// import express module and product module
var express = require('express');
product = require('./product');
review = require('./review');
var app = express();

app.use(express.bodyParser());

app.get('/', function (req, res) {
    res.json({ msg: "hello world!" });
    return;
});

app.get('/api/product/search/prodid', product.search);
app.get('/api/product/search/tag', product.search);
app.get('/api/product/search/name', product.search);
app.get('/api/product/tags', product.getAllTags);

// All routes supported in applications
app.get('/api/product/:productId?', product.getProduct);
app.get('/api/product/:productId/details', product.getProduct);
app.delete('/api/product/:productId', product.deleteProduct);
app.post('/api/product', product.addProdDetails);

// Routes for reviews
// Add
app.post('/api/product/:productId/reviews', review.addProdReview);

// Get
// GET    <product-uri>/api/product/{prodId}/reviews/{reviewId}
app.get('/api/product/:productId/reviews/:reviewId', review.getReviews);

// GET    <product-uri>/api/product/{prodId}/reviews&pageIndex={index}&pageSize={size}
app.get('/api/product/:productId/reviews', review.getReviews);

// PUT    <product-uri>/api/product/{prodId}/reviews/{reviewId}
app.put('/api/product/:productId/reviews/:reviewId', review.updateProductReview);

// This route is just a sample. If you hit it, it will ignore the body
// of the request and just insert the same static data over and over
app.post('/api/products_static', product.addProdDetailsStatic);



// setup Node.js to listen to the right port as per http://www.windowsazure.com/en-us/develop/nodejs/tutorials/getting-started/
//var port = process.env.port || 3000;
var port = process.env.port || 3000;
app.listen(port);
console.log('Listening on port ' + port);
